package chapter6;

interface Product {
    int getProduceTime();
}

public class Printer implements Product, Output {

    //MAX_CACHE_LINE从接口继承而来
    private String[] printData = new String[MAX_CACHE_LINE];
    private int dataNum = 0;

    @Override
    public int getProduceTime() {
        return 45;
    }

    @Override
    public void out() {
        while (dataNum > 0) {
            System.out.println("打印机打印:" + printData[0]);
            System.arraycopy(printData,1,printData,0,--dataNum);
        }
    }

    @Override
    public void getData(String msg) {
        if(dataNum >= MAX_CACHE_LINE) {
            System.out.println("输出队列已满，添加失败");
        } else {
            printData[dataNum++] = msg;
        }
    }

    public static void main(String[] args) {
        Output o = new Printer();
        o.getData("python");
        o.getData("java");
        o.out();
        o.getData("nodejs");
        o.getData("go");
        o.out();
        o.print("aaa", "bbb", "ccc");
        o.test();
        Product p = new Printer();
        System.out.println(p.getProduceTime());
    }
}
